Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.IO
Imports DotNetNuke
Namespace NVPortal.Modules.NVNews
    Public MustInherit Class categoriesmenu
        Inherits Entities.Modules.PortalModuleBase
        'Dim displaypage As Integer

#Region "Controls"
#End Region

#Region "Event Handlers"
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            'If IsNumeric(Settings("NVNewsDisplayPageSetting")) Then
            '    displaypage = IsNumeric(Settings("NVNewsDisplayPageSetting"))
            'End If
            If Not IsPostBack Then
                Try
                    Dim ctlNewsCategory As New NV_NewsCategoriesController
                    Dim arrNewsCategory As ArrayList
                    Dim arrNewsCategoryTemp As New ArrayList
                    arrNewsCategory = ctlNewsCategory.GetByParentId(0, PortalId)
                    Dim objNewsCategory As NV_NewsCategoriesInfo

                    For Each objNewsCategory In arrNewsCategory
                        If objNewsCategory.IsActive = True Then
                            arrNewsCategoryTemp.Add(objNewsCategory)
                        End If
                    Next

                    Me.dtlMenu.DataSource = arrNewsCategoryTemp
                    Me.dtlMenu.DataBind()

                Catch ex As Exception
                    ProcessModuleLoadException(Me, ex)
                End Try
            End If
        End Sub
#End Region

        Public Function FormatURL(ByVal sitem As String, ByVal strID As String) As String
            If IsNumeric(Settings("NVNewsDisplayPageSetting")) Then
                Return Replace(NavigateURL() & "&" & sitem & "=" & strID, String.Format("?tabid={0}&", TabId), "?tabid=" & Settings("NVNewsDisplayPageSetting") & "&")
            End If
        End Function
        Public Function FormatURLSub(ByVal sitem As String, ByVal strID As String) As String
            If IsNumeric(Settings("NVNewsDisplayPageSetting")) Then
                Return Replace(NavigateURL(168) & "&" & sitem & "=" & strID, String.Format("?tabid={0}&", TabId), "?tabid=" & Settings("NVNewsDisplayPageSetting") & "&")
            End If
        End Function

        Protected Sub dtlMenu_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dtlMenu.ItemDataBound
            If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.SelectedItem Then
                Dim dtlDetailList As DataList
                Dim hplMenu As HyperLink
                dtlDetailList = CType(e.Item.FindControl("dtlSubMenu"), DataList)
                hplMenu = CType(e.Item.FindControl("hplMenu"), HyperLink)

                Dim ctlNewsCategory As New NV_NewsCategoriesController
                Dim arrNewsCategory As ArrayList
                Dim arrNewsCategoryTemp As New ArrayList
                arrNewsCategory = ctlNewsCategory.GetByParentId(Me.dtlMenu.DataKeys(e.Item.ItemIndex).ToString, PortalId)
                If arrNewsCategory.Count > 0 Then
                    Dim objNewsCategory As NV_NewsCategoriesInfo

                    For Each objNewsCategory In arrNewsCategory
                        If objNewsCategory.IsActive = True Then
                            arrNewsCategoryTemp.Add(objNewsCategory)
                        End If
                    Next
                    dtlDetailList.DataSource = arrNewsCategoryTemp
                    dtlDetailList.DataBind()
                Else
                    'hplMenu.CssClass = "link_leftmenu2"
                    hplMenu.NavigateUrl = FormatURLSub("catid", Me.dtlMenu.DataKeys(e.Item.ItemIndex))
                End If

                'Hien thi 3 item dau mau xanh nhat
                If Me.dtlMenu.DataKeys(e.Item.ItemIndex) = 66 Or Me.dtlMenu.DataKeys(e.Item.ItemIndex) = 61 Or Me.dtlMenu.DataKeys(e.Item.ItemIndex) = 13 Then
                    hplMenu.ForeColor = System.Drawing.Color.FromName("#02509e")
                End If
            End If
        End Sub
    End Class

End Namespace
